//
//  LYNewFeatureCell.swift
//  Sina_Weibo2
//
//  Created by Elsevier on 16/5/17.
//  Copyright © 2016年 Yang Lu. All rights reserved.
//

import UIKit

class LYNewFeatureCell: UICollectionViewCell {
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }
    
    private func prepareUI(){
        contentView.addSubview(bkgImageView)
        contentView.addSubview(startButton)
        
        bkgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }
        
        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }
    }
    
    
    
    var index: Int = 0{
        didSet{
            LYPrint(items: "第\(index)页要显示")
            bkgImageView.image = UIImage(named: "new_feature_\(index + 1)")
            startButton.hidden = true
        }
    }
    
    func startAnimation(){
        startButton.hidden = false
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        
        UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue:0), animations: { () -> Void in
            self.startButton.transform = CGAffineTransformMakeScale(1, 1)
            }, completion: nil)
    }
    
    
    // MARK: - Setter & Getter 懒加载
    private lazy var bkgImageView:UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    
    private lazy var startButton: UIButton = {
        let button = UIButton()
        
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        button.hidden = true
        
        return button
    }()
}
